package me.zhengjie.modules.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.lettuce.core.dynamic.annotation.Param;
import me.zhengjie.modules.system.domain.ClassStudentCount;
import me.zhengjie.modules.system.domain.Clazzandstudent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ClazzandstudentMapper extends BaseMapper<Clazzandstudent> {

    // 根据提供的班级ID列表获取每个班级的学生数量
    @Select({
            "SELECT t1.classId AS classId, COUNT(t1.id) AS studentCount",
            "FROM clazzandstudent AS t1",
            "LEFT JOIN clazz AS t2 ON t2.id = t1.clazzId",
            "WHERE t1.classId IN",
            "<foreach collection='classIds' item='item' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "GROUP BY t1.classId"
    })
    List<ClassStudentCount> getClassStudentCounts(List<Integer> classIds);
}
